<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 将数组中值为 0 的项去掉，将不为 0 的值存入一个新的数组，生成新的数组。 -->
    <!--  -->
    <script>
        var arr = [1,0,2,0,3,0,4,0,5,0];
        var arr1 = [];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] != 0) {
                arr1.push(arr[i]);
            }
        }
        for (var i = 0; i<arr.length; i++) {
            if (arr[i] === 0) {
                arr.splice(i,1);
            }
        }
        console.log(arr);
        console.log(arr1);
    </script>
</body>
</html>